/**
 * amis v6.13.0
 * build time: 2025-08-12
 * Copyright 2018-2025 baidu
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var tslib = require('tslib');
var React = require('react');
var amisCore = require('amis-core');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);

var __react_jsx__ = require('react');
var _J$X_ = (__react_jsx__["default"] || __react_jsx__).createElement;
var _J$F_ = (__react_jsx__["default"] || __react_jsx__).Fragment;


;/**
 * @file 用于表格类型的展现效果，界面可定制化能力更强
 */
var defaultPadding = 'var(--TableCell-paddingY) var(--TableCell-paddingX)';
var TableView = /** @class */function (_super) {
  tslib.__extends(TableView, _super);
  function TableView(props) {
    return _super.call(this, props) || this;
  }
  TableView.prototype.renderTd = function (td, colIndex, rowIndex) {
    var _a;
    var _b = this.props,
      border = _b.border,
      borderColor = _b.borderColor,
      render = _b.render,
      data = _b.data,
      padding = _b.padding;
    var key = "td-".concat(colIndex);
    var styleBorder;
    if (border) {
      styleBorder = "1px solid ".concat(borderColor);
    }
    return amisCore.isVisible(td, data) ? _J$X_("td", {
      style: tslib.__assign({
        border: styleBorder,
        color: td.color,
        fontWeight: td.bold ? 'bold' : 'normal',
        background: td.background,
        padding: (_a = td.padding) !== null && _a !== void 0 ? _a : padding,
        width: td.width || 'auto',
        textAlign: td.align || 'left',
        verticalAlign: td.valign || 'center'
      }, td.style),
      align: td.align,
      valign: td.valign,
      rowSpan: td.rowspan,
      colSpan: td.colspan,
      key: key
    }, this.renderTdBody(td.body)) : null;
  };
  TableView.prototype.renderTdBody = function (body) {
    var render = this.props.render;
    return render('td', body || '');
  };
  TableView.prototype.renderTds = function (tds, rowIndex) {
    var _this = this;
    var data = this.props.data;
    return tds.map(function (td, colIndex) {
      return _this.renderTd(amisCore.resolveMappingObject(td, data), colIndex, rowIndex);
    });
  };
  TableView.prototype.renderTr = function (tr, rowIndex) {
    var key = "tr-".concat(rowIndex);
    var data = this.props.data;
    return amisCore.isVisible(tr, data) ? _J$X_("tr", {
      style: tslib.__assign({
        height: tr.height,
        background: tr.background
      }, tr.style),
      key: key
    }, this.renderTds(tr.tds || [], rowIndex)) : null;
  };
  TableView.prototype.renderTrs = function (trs) {
    var _this = this;
    var data = this.props.data;
    var tr = trs.map(function (tr, rowIndex) {
      return _this.renderTr(amisCore.resolveMappingObject(tr, data), rowIndex);
    });
    return tr;
  };
  TableView.prototype.renderCols = function () {
    var _a = this.props,
      cols = _a.cols,
      data = _a.data;
    if (cols) {
      var colsElement = cols.map(function (col) {
        col = amisCore.resolveMappingObject(col, data);
        return _J$X_("col", {
          span: col.span,
          style: col.style
        });
      });
      return _J$X_("colgroup", null, colsElement);
    }
    return null;
  };
  TableView.prototype.renderCaption = function () {
    if (this.props.caption) {
      return _J$X_("caption", {
        style: {
          captionSide: this.props.captionSide === 'bottom' ? 'bottom' : 'top'
        }
      }, this.props.caption);
    }
    return null;
  };
  TableView.prototype.render = function () {
    var _a = this.props,
      width = _a.width,
      _b = _a.trs,
      trs = _b === void 0 ? [] : _b,
      cx = _a.classnames,
      className = _a.className,
      id = _a.id,
      wrapperCustomStyle = _a.wrapperCustomStyle,
      env = _a.env,
      themeCss = _a.themeCss,
      style = _a.style;
    var renderNode = _J$X_("table", {
      className: cx('TableView', className, amisCore.setThemeClassName(tslib.__assign(tslib.__assign({}, this.props), {
        name: 'baseControlClassName',
        id: id,
        themeCss: themeCss
      })), amisCore.setThemeClassName(tslib.__assign(tslib.__assign({}, this.props), {
        name: 'wrapperCustomStyle',
        id: id,
        themeCss: wrapperCustomStyle
      }))),
      style: {
        width: width,
        borderCollapse: 'collapse'
      },
      "data-id": id
    }, this.renderCaption(), this.renderCols(), _J$X_("tbody", null, this.renderTrs(trs)), _J$X_(amisCore.CustomStyle, tslib.__assign({}, this.props, {
      config: {
        wrapperCustomStyle: wrapperCustomStyle,
        id: id,
        themeCss: themeCss,
        classNames: [{
          key: 'baseControlClassName'
        }]
      },
      env: env
    })));
    if (style && Object.keys(style).length) {
      return _J$X_("div", {
        className: "ae-TableViewEditor",
        style: style
      }, renderNode);
    }
    return renderNode;
  };
  TableView.defaultProps = {
    padding: defaultPadding,
    width: '100%',
    border: true,
    borderColor: 'var(--borderColor)'
  };
  return TableView;
}(React__default["default"].Component);
var TableViewRenderer = /** @class */function (_super) {
  tslib.__extends(TableViewRenderer, _super);
  function TableViewRenderer() {
    return _super !== null && _super.apply(this, arguments) || this;
  }
  TableViewRenderer = tslib.__decorate([amisCore.Renderer({
    type: 'table-view',
    autoVar: true
  })], TableViewRenderer);
  return TableViewRenderer;
}(TableView);

exports.TableViewRenderer = TableViewRenderer;
exports["default"] = TableView;
